package com.besovideo.mpu;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.smarteye.mpu.MPUGlobal;
import com.smarteye.mpu.MainService.Connection;

public class FaceRecognitionDialog extends Dialog {

	MainActivity context;
	int lay;
	boolean bFaceTrack;
	Connection mConnection;
	RadioGroup m_RadioGroup;
	RadioButton m_RadioButtonFaceRecognitionOpen;
	RadioButton m_RadioButtonFaceRecognitionClose;

	public FaceRecognitionDialog(MainActivity context) {
		super(context, R.style.TransparentDialogHaveTitle);
		this.context = context;
		this.lay = R.layout.face_recognition_set_dialog;
		mConnection = ((MPUGlobal) ((MainActivity) context).getApplication())
				.getConnection();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(lay);
		m_RadioButtonFaceRecognitionOpen = (RadioButton) findViewById(R.id.radioButtonFaceCognitionOpen);
		m_RadioButtonFaceRecognitionClose = (RadioButton) findViewById(R.id.radioButtonFaceCognitionClose);
		m_RadioGroup = (RadioGroup) findViewById(R.id.radioGroupFaceRecognition);
		SelectSet();

		m_RadioGroup
				.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
					@Override
					public void onCheckedChanged(RadioGroup arg0, int checkedId) {
						// TODO Auto-generated method stub
						MainActivity parent = (MainActivity) context;
						if (checkedId == m_RadioButtonFaceRecognitionOpen
								.getId()) {
							parent.subConfigMenuListViewAdapter
									.setText(
											MainActivity.SubConfigMenuEnum.SUB_MENU_FACE_RECOGNITION
													.value(),
											m_RadioButtonFaceRecognitionOpen
													.getText().toString());
							context.faceDetech(true);
						} else if (checkedId == m_RadioButtonFaceRecognitionClose
								.getId()) {
							parent.subConfigMenuListViewAdapter
									.setText(
											MainActivity.SubConfigMenuEnum.SUB_MENU_FACE_RECOGNITION
													.value(),
											m_RadioButtonFaceRecognitionClose
													.getText().toString());
							context.faceDetech(false);
						}
						parent.subConfigMenuListViewAdapter
								.notifyDataSetChanged();
						dismiss();
					}
				});
	}

	private void SelectSet() {
		bFaceTrack = context.isbFaceTrack();
		if (bFaceTrack) {
			m_RadioGroup.check(m_RadioButtonFaceRecognitionOpen.getId());
		} else {
			m_RadioGroup.check(m_RadioButtonFaceRecognitionClose.getId());
		}
	}
}